package com.shd.edanpei.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.shd.edanpei.R;
import com.shd.edanpei.bean.ProjectBean;
import com.shd.edanpei.bean.ProjectDataBean;
import com.shd.edanpei.bean.ValueBean;
import com.shd.edanpei.util.PhotoUrl;

import cn.sharesdk.alipay.friends.Alipay;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;


public class OnKeyShareDialog extends Dialog {
protected ValueBean valueBean;
 private    ProjectDataBean projectDataBean;
   private Context context;
    public OnKeyShareDialog(@NonNull Context context,ValueBean valueBean,ProjectDataBean model) {
        super(context);
        this.valueBean=valueBean;
        this.projectDataBean=model;
        this.context=context;
        initView();
    }

    public OnKeyShareDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public OnKeyShareDialog(@NonNull Context context, boolean cancelable
            , @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    private void initView() {
        this.setContentView(R.layout.dialog_onkey_share);
        Glide.with(getContext()).load(projectDataBean.getResult()).into((ImageView) findViewById(R.id.regist_reg));
        //Glide.with(this).load(image).into(ivImage);
        findViewById(R.id.share_QQ).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare(QQ.NAME);
            }
        });
        findViewById(R.id.share_WeChat).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare(Wechat.NAME);
            }
        });
        findViewById(R.id.share_WeChatMoments).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare(WechatMoments.NAME);
            }
        });
        findViewById(R.id.share_AliPay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare(Alipay.NAME);
            }
        });
    }

    private final String SHARE_URL = "https://www.yingkd.com/edp/H5/links-dowunload.html";

    private void showShare(String platform) {

        OnekeyShare oks = new OnekeyShare();
        oks.disableSSOWhenAuthorize();
//        //图片url

        //oks.setImageData(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.logo));
        oks.setImageData(PhotoUrl.returnBitMap(projectDataBean.getSharePic()));
        oks.setImageUrl(projectDataBean.getSharePic());
//        oks.setImageUrl("http://img03.tooopen.com/uploadfile/downs/images/20110714/sy_20110714135215645030.jpg");
        if (platform.equals(QQ.NAME)) {
            oks.setTitleUrl(projectDataBean.getShareUrl());
        } else {
            oks.setUrl(projectDataBean.getShareUrl());
        }
        oks.setTitle(projectDataBean.getShareTitle());
        oks.setText(projectDataBean.getShareContent());
        oks.setPlatform(platform);
        oks.show(getContext());
    }

}
